package cn.cloud9.designpattern.dp03prototype;

import java.util.Arrays;

/**
 * @author OnCloud9
 * @description
 * @project Java
 * @date 2022年05月22日 16:51
 */
public class BeanUtil {

    public static <T> T copyInstance(Object target, Class<T> TClass) {
        try {
            final T t = TClass.newInstance();
            Arrays.stream(TClass.getDeclaredFields()).forEach(field -> {
                try {
                    // 允许被反射访问
                    field.setAccessible(true);
                    // 对新的对象设置目标的属性
                    field.set(t, field.get(target));
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            });

        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return null;
    }
}
